package c;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/ForwardServlet")
public class ForwardServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获得虚拟目录
        String path = request.getContextPath();
        System.out.println(path);
        //2.request作为域对象使用
        System.out.println("请求："+ request);
        request.setAttribute("name","lucy");
        //3.请求转发功能   在ForwardServlet1中获取存入的数据
        //3.1 获取请求的转发器
        RequestDispatcher rd = request.getRequestDispatcher("/ForwardServlet1");  //参数，要转发到什么资源中
        rd.forward(request,response);

        //合并:request.getRequestDispatcher("/ForwardServlet1").forward(request,response);
    }
}
